package com.iplant.basic.serviceImpl;

import java.util.Calendar;
import java.util.List;

import com.iplant.base.po.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.basic.service.CFGService;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.basic.service.po.cfg.*;
import com.iplant.basic.serviceImpl.dao.cfg.*;

@Service
public class CFGServiceImpl implements CFGService {
    private static Logger logger = LoggerFactory.getLogger(CFGServiceImpl.class);


    private static CFGService _instance = null;

    public static CFGService getInstance() {
        if (_instance == null) _instance = new CFGServiceImpl();

        return _instance;
    }

    @Override
    public ServiceResult<List<CFGCalendar>> CFG_QueryHoliday(BMSEmployee wLoginUser, int wFactoryID, int wWorkshopID,int wWorkAreaID,int wStationID,
                                                             int wYear, int wMonth, Calendar wStartDate, Calendar wEndDate, int wIsCreate, Pagination wPagination) {
        // TODO Auto-generated method stub
        ServiceResult<List<CFGCalendar>> wResult = new ServiceResult<List<CFGCalendar>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>();
            wErrorCode.set(0);
            if (wYear > 0 && wMonth >= 0) {
                wResult.Result = CFGCalendarDAO.getInstance().CFG_QueryHoliday(wLoginUser, wFactoryID, wWorkshopID,wWorkAreaID,wStationID, wYear, wMonth, wIsCreate, wPagination,
                        wErrorCode);
            } else {
                wResult.Result = CFGCalendarDAO.getInstance().CFG_QueryHoliday(wLoginUser, wFactoryID, wWorkshopID,wWorkAreaID,wStationID, wStartDate, wEndDate, wIsCreate, wPagination,
                        wErrorCode);
            }
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error(e.toString());
        }
        return wResult;
    }

}
